# import matplotlib.pyplot as plt
# import numpy as np
import pandas as pd
# import sklearn
# import re

# 这个交叉验证被模型选择替代掉了，在高级版本中不再支持了
# 引入交叉验证
# from sklearn import train_test_split

from sklearn.model_selection import train_test_split

# 引入决策树
import sklearn.tree as tree
data = pd.read_excel('loan.xlsx')
target = data['Type']
# 删除一个列
data.drop('Type', axis='columns', inplace=True)
# 哦！这里将数据分为两组，每组都有对应的x和y
train_data, test_data, train_target, test_target = train_test_split(
    data, target, test_size=0.4, train_size=0.6, random_state=12345)

# 这里是决策树，损失函数采用了软分类entropy
clf_1 = tree.DecisionTreeClassifier(criterion='entropy')
# 训练，训练完之后会自己更新模型的
clf_1.fit(train_data, train_target)
# 预测
train_est = clf_1.predict(train_data)
train_est_p = clf_1.predict_proba(train_data)[:, 1]
test_est = clf_1.predict(test_data)
print(test_est)
